<%@page contentType="text/html" pageEncoding="UTF-8" %>
<%@ page import="java.sql.*" %>

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>BoxOffice.jsp</title>
        <link href="/CineScope2014FO/css/principal.css" rel="stylesheet" type="text/css">
    </head>

    <body>
        <%@include file="../jsp/_entete.jsp" %>
        <%@include file="../jsp/_rechercher.jsp" %>
        <%@include file="../jsp/_sommaire.jsp" %>

        <div id="centre">

            <h3>Box office</h3>

            <%-- Modele --%>
            <%!
            %>

            <%        StringBuilder lsbResultat = new StringBuilder("");
                Connection lcn;
                String lsSQL;
                PreparedStatement lpst;
                ResultSet lrs;
                try {
                    // --- Connexion
                    //Class.forName("org.gjt.mm.mysql.Driver");
                    //lcn = DriverManager.getConnection("jdbc:mysql://localhost:3306/cineScope2014", "root", "");
                    lcn = (Connection)session.getAttribute("connexionCineScope");

                    // --- SELECT
                    //lsSQL = "SELECT titre_film, total_entrees FROM film ORDER BY total_entrees DESC LIMIT 0,20";
                    lsSQL = "CALL box_office()";
                    lpst = lcn.prepareStatement(lsSQL);
                    lrs = lpst.executeQuery();
                    lsbResultat.append("<table>");
                    lsbResultat.append("<tr>");
                    lsbResultat.append("<th>");
                    lsbResultat.append("Titre");
                    lsbResultat.append("</th>");

                    lsbResultat.append("<th>");
                    lsbResultat.append("Total des entrées");
                    lsbResultat.append("</th>");
                    lsbResultat.append("</tr>");
                    while (lrs.next()) {
                        lsbResultat.append("<tr>");
                        lsbResultat.append("<td>");
                        lsbResultat.append(lrs.getString(1));
                        lsbResultat.append("</td>");
                        lsbResultat.append("<td>");
                        lsbResultat.append(lrs.getString(2));
                        lsbResultat.append("</td>");
                        lsbResultat.append("</tr>");
                    }
                    lsbResultat.append("</table>");
                    // --- Fermeture de la commande
                    lpst.close();
                    // --- Fermeture du curseur
                    lrs.close();

                    // --- Deconnexion
                    //lcn.close();
                } catch (Exception e) {
                    lsbResultat.append("<br/>");
                    lsbResultat.append(e.getMessage());
                }

                if (request.getParameter("message") != null) {
                    lsbResultat.append("<br/>");
                    lsbResultat.append(request.getParameter("message"));
                }

                out.println(lsbResultat.toString());
            %>

        </div>

        <%@include file="../jsp/_pied.jsp" %>
    </body>
</html>